#include "gm3d.h"

void GM3D::AddModels(std::string modentity_file){
	string temp_str;
	stringstream temp_ss;
	modelist temp_list;

	ifstream infile;
	gctl::open_infile(infile, modentity_file);

	while(getline(infile, temp_str)){
		if (temp_str[0] == '#') continue;
		else{
			//按每行5个数据解析 初始化为含观测值与不确定度的观测点
			gctl::str2ss(temp_str, temp_ss);
			temp_ss >> temp_list.mod_type >> temp_list.val_type >> temp_list.mod_value 
				>> temp_list.mod_para;

			if (temp_ss.fail())
				throw GM3D_MODEL_INIT_FAIL;

			model_list_.push_back(temp_list);
		}
	}
	infile.close();

	for (int i = 0; i < model_list_.size(); i++)
	{
		if (model_list_[i].mod_type == "regular_block"){
			AddRegularBlock(model_list_[i]);
		}
		else if (model_list_[i].mod_type == "tilted_block"){
			AddTiltedBlock(model_list_[i]);
		}
		else if (model_list_[i].mod_type == "sphere"){
			AddSphereBlock(model_list_[i]);
		}
		else if (model_list_[i].mod_type == "interface"){
			AddInterfaceBlock(model_list_[i]);
		}
		else throw GM3D_INVALID_MODEL_TYPE;
	}
	return;
}